<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>飞机修理任务级别分析统计系统</title>
    <#assign base=request.contextPath  />
    <base id="base" href="${base}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, adminUser-scalable=0">
    <link rel="stylesheet" href="${base}/static/win10/component/layui/css/layui.css" media="all">
    <script>
        var base = "${base}";
    </script>
    <style>
        #search {
            position: relative;
        }

        .search-list {
            width: 120px;
            /* height:100px; */
            /*background: #f46;*/
            position: absolute;
            left: 0;
            top: 38px;
            display: none;
        }

        #search:hover .search-list {
            display: block;
        }

        .search-item {
            height: 38px;
            width: 100%;
            color: #000;
            position: relative;
        }

        .item-title {
            color: aqua;
            font-size: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            /*background: blueviolet;*/
            font-size: 14px;
            color: #fff;
            border-top: 1px solid #fff;
            border-right: 1px solid #fff;
            cursor: pointer;

        }

        .item-child {
            position: absolute;
            left: 120px;
            /*width: 120px;*/
            /*height: 38px;*/
            top: 0px;
            position: absolute;
            font-size: 24px;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            display: none;
            color: #fff;
            font-size: 14px;
            border-top: 1px solid #fff;
            cursor: pointer;

        }

        .search-item:hover .item-child {
            display: flex;
        }
    </style>
</head>
<body>
<br>


<#--<div class="demoTable" style="margin-left: 15px;">-->
<#--    <form class="layui-form " action="" >-->
<#--    <div class="layui-form-item">-->
<#--        <label>修理项目大类</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="item" id="item" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理子项目</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="child" id="child" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理科目</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="forRepair" id="forRepair" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理原因及目的</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="subjects" id="subjects" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理方法</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="method" id="method" autocomplete="off">-->
<#--        </div>-->
<#--        <label>发生频度</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="moreFrequent" id="moreFrequent" autocomplete="off">-->
<#--        </div>-->
<#--        <label>工具设备</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="equipment" id="equipment" autocomplete="off">-->
<#--        </div>-->
<#--        <label>耗材</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="consumables" id="consumables" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理难度</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="difficulty" id="difficulty" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理费用估计</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="cost" id="cost" autocomplete="off">-->
<#--        </div>-->
<#--        <label>修理级别</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="level" id="level" autocomplete="off">-->
<#--        </div>-->
<#--        <label>创建时间</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="createTime" id="createTime" autocomplete="off">-->
<#--        </div>-->
<#--        <label>更新时间</label>-->
<#--        <div class="layui-inline">-->
<#--            <input class="layui-input" name="updateTime" id="updateTime" autocomplete="off">-->
<#--        </div>-->
<#--        <button type="button" class="layui-btn" data-type="reload">-->
<#--            <i class="layui-icon layui-icon-search">搜索</i>-->
<#--        </button>-->
<#--    </div>-->
<#--    </form>-->
<#--</div>-->
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">

    <form class="layui-form " action="">


        <div class="layui-form-item demoTable" style="margin-left: 15px;">
            <div class="layui-btn-group" style="display: flex">


                <div id="search">
                    <button data-type="button" type="button" class="layui-btn" lay-event="">数据导入/导出</button>
                    <div class="search-list">
                        <div class="search-item">
                            <button type="button" id="imports" class="layui-btn item-title" style="width:120px;"
                                    lay-event="import">
                                导入
                            </button>
                            <button type="button" id="export" class="layui-btn item-title" style="width:120px;"
                                    lay-event="export">
                                导出
                            </button>
                            <a href="http://localhost:9527/analyse/repairMethod/get/methodRtemplate">
                                <button type="button" class="layui-btn" style="width:120px;border-top:1px solid #fff"
                                        lay-event="template">模板
                                </button>
                            </a>

                        </div>
                    </div>
                </div>
                <div id="search">
                    <#--                    <button type="button" class="layui-btn" lay-event="select" style="border-left: 1px solid rgba(255,255,255,.5);-->
                    <#--                ">查询-->
                    <#--                    </button>-->
                    <button type="button" class="layui-btn" id="repairProject" lay-event="repairProject">修复项目</button>
                    <div class="search-list">
                        <div class="search-item">
                            <#--                            <button type="button" class="layui-btn item-title item-repair" style="width:120px;" lay-event="">-->
                            <#--                                按照修理难度-->
                            <#--                            </button>-->
                            <#if items?? && items?size gt 0>
                                <#list items as item>
                                    <button type="button" class="layui-btn item-title item-repair" style="width:120px;"
                                            lay-event="">
                                        ${item}
                                    </button>
                                </#list>
                            </#if>


                        </div>
                    </div>
                </div>

                <#--                <button type="button" class="layui-btn" lay-event="select">查询</button>-->
                <div id="search">
                    <button type="button" class="layui-btn" lay-event="select" style="border-left: 1px solid rgba(255,255,255,.5);
                ">查询
                    </button>
                    <div class="search-list">
                        <div class="search-item">
                            <button type="button" class="layui-btn item-title" style="width:120px;" lay-event="">
                                按照修理难度
                            </button>

                            <div class="item-child">
                                <button type="button" id="easy" class="layui-btn"
                                        style="width:120px;border-top: 1px solid #fff;"
                                        lay-event="easy">容易
                                </button>

                                <button type="button" id="general" class="layui-btn"
                                        style="width:120px;border-top: 1px solid #fff;"
                                        lay-event="general">一般
                                </button>

                                <button type="button" id="hard" class="layui-btn"
                                        style="width:120px;border-top: 1px solid #fff;"
                                        lay-event="hard">困难
                                </button>


                            </div>
                        </div>

                        <div class="search-item">
                            <button type="button" class="layui-btn item-title" style="width:120px;" lay-event="">
                                按照修理级别
                            </button>
                            <div class="item-child">
                                <button type="button" id="troopLevel" class="layui-btn" style="width:120px;"
                                        lay-event="troopLevel">部队级
                                </button>
                                <button type="button" id="grassroots" class="layui-btn"
                                        style="width:120px;border-top: 1px solid #fff;"
                                        lay-event="grassroots">基层级
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <button type="button" class="layui-btn" lay-event="add">数据库维护</button>

                <button type="button" class="layui-btn" lay-event="del">删除</button>

                <button type="button" class="layui-btn" lay-event="help">帮助</button>


            </div>
        </div>

    </form>
</script>

<script src="${base}/static/win10/component/layui/layui.js?t=1"></script>
<script src="${base}/static/win10/js/jquery-1.8.3.min.js?t=1"></script>
<script>
    layui.use(['table', 'form', 'layer', 'upload'], function () {

        // 设置全局变量以保存选中行信息
        var ids = new Array();
        // 保存当前页全部数据id，点击全选时使用
        var tableIds = new Array();


        var form = layui.form
            , layer = layui.layer, table = layui.table, upload = layui.upload;

        var exportData; //记录信息


        var ins1 = table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test'
            , url: base + '/analyse/repair/admin/findRepairByPage'
            , toolbar: '#toolbarDemo'
            , cols: [[
                {type: 'checkbox'},
                // {field: 'repairId', title: 'id'},
                {field: 'item', title: '修理项目大类'},
                {field: 'child', title: '修理子项目'},
                {field: 'forRepair', title: '修理科目'},
                {field: 'subjects', title: '修理原因及目的'},
                {field: 'method', title: '修理方法'},
                {field: 'moreFrequent', title: '发生频度'},
                {field: 'equipment', title: '工具设备'},
                {field: 'consumables', title: '耗材'},
                {field: 'difficulty', title: '修理难度'},
                {field: 'cost', title: '修理费用估计'},
                {field: 'level', title: '修理级别'},
                {field: 'createTime', title: '创建时间',templet:function (obj) {
                        return timestampToTime(obj.createTime);
                    }},
                {field: 'updateTime', title: '更新时间',templet:function (obj) {
                        return timestampToTime(obj.updateTime);
                    }
                }
            ]]
            , page: true
            , id: 'testReload'
            , done: function (res) {

                // 设置当前页全部数据id到全局变量
                tableIds = res.data.map(function (value) {

                    return value.repairId;
                });


                // 设置当前页选中项
                $.each(res.data, function (idx, val) {


                    if (ids.indexOf(val.repairId) > -1) {

                        val["LAY_CHECKED"] = 'true';

                        //找到对应数据改变勾选样式，呈现出选中效果
                        let index = val['LAY_TABLE_INDEX'];


                        $('tr[data-index=' + index + '] input[type="toolbar"]').click();
                        form.render('toolbar'); //刷新toolbar选择框渲染
                    }
                });
                // 获取表格勾选状态，全选中时设置全选框选中
                var checkStatus = table.checkStatus('test');
                if (checkStatus.isAll) {
                    $('.layui-table-header th[data-field="0"] input[type="toolbar"]').prop('checked', true);
                    form.render('toolbar'); //刷新toolbar选择框渲染
                }

                exportData = res.data;//导出的数据


                //获取节点id
                var tableId = this.id;
                var tableElem = this.elem;
                //table render出来实际显示的table组件
                var tableViewElem = tableElem.next();


                upload.render({
                    elem: tableViewElem.find('#imports') //绑定元素
                    , url: base + '/analyse/repair/Import/'    //上传接口
                    , accept: "file"
                    , before: function () {
                    }
                    , done: function (res) {
                        if (res.code == 200) {
                            //上传完毕回调
                            layer.msg("上传成功!")
                            window.location.reload();
                        } else {
                            layer.msg(res.message)
                        }

                    }
                    , error: function (res) {
                        //请求异常回调
                        alert(res.message)
                    }
                });


            }


        });

        //
        // $("#hard").on("click", function () {
        //
        //
        //     var formDate = {
        //         companyName: $("#companyName").val(),
        //         companyQualification: $("#companyQualification").val(),
        //         companyLicenseImg: $("#companyLicenseImg").val(),
        //         userId: $("#userId").val(),
        //         companyIsDelete: $("#companyIsDelete").val(),
        //         companyRemarks: $("#companyRemarks").val(),
        //         areaId:/*$("#areaId").val()*/areaids,
        //         companyScale: $("#companyScale").val(),
        //         companyLogo: $("#companyLogo").val()
        //     }
        //     $.ajax({
        //         type: "POST",
        //         url: base + "/WeChatUser/wechatCompany/admin/addWechatCompany",
        //         data: formDate,
        //         success: function (data) {
        //             layer.msg(data.message)
        //             if (data.code === 200) {
        //                 window.location.href = base + "/WeChatUser/wechatCompany/admin/main.html"
        //             } else {
        //
        //             }
        //         }
        //     });
        // })


        //搜索
        var $ = layui.$
            , active = {
                reload: function () {
                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            item: $("#item").val(),
                            child: $("#child").val(),
                            forRepair: $("#forRepair").val(),
                            subjects: $("#subjects").val(),
                            method: $("#method").val(),
                            moreFrequent: $("#moreFrequent").val(),
                            equipment: $("#equipment").val(),
                            consumables: $("#consumables").val(),
                            difficulty: $("#difficulty").val(),
                            cost: $("#cost").val(),
                            level: $("#level").val(),
                            createTime: $("#createTime").val(),
                            updateTime: $("#updateTime").val()
                        }
                    }, 'data');
                }
            }


        ;


        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data;  //获取选中行数据

            var idList = []
            for (let i = 0; i < data.length; i++) {
                idList.push(data[i].repairId)
            }


            switch (obj.event) {
                case 'add':
                    //请继续补充以下逻辑
                    window.location.href = base + "/analyse/repair/admin/addRepairHtml"
                    break;
                case 'edit':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    //请继续补充以下逻辑
                    window.location.href = base + "/analyse/repair/admin/editRepairHtml?id=" + data[0].repairId
                    break;
                case 'show':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    //请继续补充以下逻辑
                    window.location.href = base + "/analyse/repair/admin/showRepairHtml?id=" + data[0].repairId
                    break;
                case 'del':
                    if (data.length === 0) {
                        layer.alert("请选择一条数据")
                        return;
                    }
                    layer.confirm('真的要删除吗?', function (index) {
                        $.ajax({
                            type: "GET",
                            url: base + '/analyse/repair/admin/delRepair',
                            data: {"datas": idList},
                            dataType: "json",
                            success: function (data) {
                                if (data.code === 200) {
                                    layer.msg(data.message)
                                    setTimeout(function () {
                                        window.location.reload();
                                    }, 500)
                                } else {
                                    layer.msg(data.message)
                                }
                            }
                        });
                    });
                    break;
                case 'export':
                    table.exportFile(ins1.config.id, exportData, 'xls');
                    break;
                case 'easy':
                    console.log("点击了容易!")
                    //搜索
                    ins1.reload({
                        page: {curr: 1},
                        where: {
                            difficulty: "容易",
                        }
                    })

                    break;
                case 'general':
                    console.log("点击了一般!")
                    //搜索
                    ins1.reload({
                        page: {curr: 1},
                        where: {
                            difficulty: "一般",
                        }
                    })

                    break;
                case 'hard':
                    console.log("点击了容易!")
                    //搜索
                    ins1.reload({
                        page: {curr: 1},
                        where: {
                            difficulty: "困难",
                            level: $("#level").val(),
                        }
                    })

                    break;
                case 'grassroots':
                    console.log("基层级!")
                    //搜索
                    ins1.reload({
                        page: {curr: 1},
                        where: {
                            level: "基层级",
                        }
                    })

                    break;
                case 'troopLevel':
                    console.log("点击了容易!")
                    //搜索
                    ins1.reload({
                        page: {curr: 1},
                        where: {
                            level: "部队级",
                        }
                    })

                    break;

            }

            ;
        });

        //监听行双击事件
        table.on('rowDouble(test)', function (obj) {
            var data = obj.data;
            window.location.href = base + "/analyse/repair/admin/showRepairHtml?id=" + data.repairId
        });
    })



    function timestampToTime(timestamp) {
        var date = new Date(Number(timestamp));//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>
</body>
</html>